import { User } from "./user"

export async function try_login(nickname:string, password:string){
    console.log("Login",nickname,password)
    const api='/api/identity/login'
    const res=await fetch(api,{
        method:'post',
        body:JSON.stringify({nickname,password}),
        headers:{'Content-Type':'application/json;charset=utf-8'}
    })
    if (res.ok==false) {
        console.error('Login failed!')
        console.dir(res)
        throw await res.text();
    }
    const user:User= await res.json();
    console.log('Login ok:',user);
    return user;
}

